import { View } from "../../../../mvc/core/View";
import { PetSkillItem } from "./PetSkillItem";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { SPetInfo } from "../../../../../Message/Game/SPetInfo";
import { SPetSkill } from "../../../../../Message/Game/SPetSkill";
import { SkillConfig } from "../../../resource/SkillConfig";
type int = number;
//class PetSkillListPanel
    
    export  class PetSkillListPanel extends View
    {
        constructor(arg1: Boolean=false)
        {
            super();
            this._skillItemArray = [];
            this.init(arg1);
            return;
        }

        public init(arg1: Boolean=false): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            while (loc3 < 14) 
            {
                loc1 = new PetSkillItem();
                loc1.isDig = arg1;
                loc1.setSize(32, 32);
                loc1.y = 3;
                if (loc3 < 12) 
                {
                    loc2 = GlobalClass.getBitmap(ImagesConst.PackItemBg);
                    loc2.x = loc3 * 40;
                    loc1.x = 3 + loc3 * 40;
                    if (loc3 < 4) 
                    {
                        loc1.type = 0;
                    }
                    else if (loc3 >= 4 && loc3 < 12) 
                    {
                        loc1.type = 1;
                    }
                }
                else 
                {
                    loc2 = GlobalClass.getBitmap(ImagesConst.YellowItemBg);
                    loc2.x = 10 + loc3 * 40;
                    loc1.x = 13 + loc3 * 40;
                    loc1.type = 2;
                }
                loc2.width = 38;
                loc2.height = 38;
                loc1.index = loc3;
                this._skillItemArray.push(loc1);
                if (loc3 < 12) 
                {
                    this.addChild(loc2);
                    this.addChild(loc1);
                }
                loc1.addEventListener(flash.events.MouseEvent.CLICK, this.onSkillItemClickHandler);
                ++loc3;
            }
            return;
        }

        protected updateByPetInfo(arg1: SPetInfo): void
        {
            var loc2=0;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc7=null;
            var loc8=0;
            this._petInfo = arg1;
            this.clearSkillList();
            var loc1=12;
            var loc3=[];
            if (arg1) 
            {
                loc2 = arg1.maxSkillAmount;
                loc3 = arg1.skills;
                loc6 = 0;
                while (loc6 < loc3.length) 
                {
                    loc4 = loc3[loc6] as SPetSkill;
                    if (SkillConfig.instance.isSpecialSkill(loc4.skillId)) 
                    {
                        (loc5 = this._skillItemArray[loc1]).index = loc1;
                        ++loc1;
                    }
                    else 
                    {
                        (loc5 = this._skillItemArray[(loc4.pos - 1)]).index = loc6;
                    }
                    this.setSkill(loc5, loc4);
                    ++loc6;
                }
                loc8 = 0;
                while (loc8 < this._skillItemArray.length) 
                {
                    (loc7 = this._skillItemArray[loc8]).petInfo = arg1;
                    if (loc8 < 12) 
                    {
                        if (loc8 < loc2) 
                        {
                            loc7.type = 0;
                        }
                        else 
                        {
                            loc7.type = 1;
                        }
                    }
                    else if (loc8 != 12) 
                    {
                        if (loc8 == 13) 
                        {
                            loc7.type = arg1.reinLevel >= 2 ? 0 : 2;
                        }
                    }
                    else 
                    {
                        loc7.type = arg1.reinLevel >= 1 ? 0 : 2;
                    }
                    ++loc8;
                }
            }
            return;
        }

        protected setSkill(arg1: PetSkillItem, arg2: SPetSkill): void
        {
            arg1.skill = arg2;
            return;
        }

        protected onSkillItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=0;
            var loc1=arg1.target as PetSkillItem;
            if (loc1) 
            {
                this._selectedSkillInfo = loc1.skill;
                if (this._selectedSkillInfo) 
                {
                    loc2 = loc1.index;
                }
                else 
                {
                    loc2 = -1;
                }
                this.selectedIndex = loc2;
            }
            return;
        }

        public get selectedSkillInfo(): SPetSkill
        {
            return this._selectedSkillInfo;
        }

        public set selectedSkillInfo(arg1: SPetSkill)
        {
            this._selectedSkillInfo = arg1;
            return;
        }

        public get petInfo(): SPetInfo
        {
            return this._petInfo;
        }

        public set petInfo(arg1: SPetInfo)
        {
            this._petInfo = arg1;
            this.updateByPetInfo(this._petInfo);
            return;
        }

        protected clearSkillList(): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < this._skillItemArray.length) 
            {
                loc1 = this._skillItemArray[loc2];
                this.setSkill(loc1, null);
                ++loc2;
            }
            this._selectedSkillInfo = null;
            this.selectedIndex = -1;
            return;
        }

        public get selectedIndex(): int
        {
            return this._selectedIndex;
        }

        public set selectedIndex(arg1: int)
        {
            var loc1=null;
            this._selectedIndex = arg1;
            var loc2=0;
            while (loc2 < this._skillItemArray.length) 
            {
                loc1 = this._skillItemArray[loc2];
                if (arg1 != loc2) 
                {
                    loc1.selected = false;
                }
                else 
                {
                    loc1.selected = true;
                }
                ++loc2;
            }
            this.dispatchEvent(new Object /* flash.events.Event */(flash.events.Event.CHANGE, true));
            return;
        }

        public clear(): void
        {
            this.clearSkillList();
            return;
        }

        public get selectedPetSkillItem(): PetSkillItem
        {
            return this._skillItemArray[this._selectedIndex];
        }

        protected /* var */_skillItemArray: Array<any>;

        protected /* var */_petInfo: SPetInfo;

        protected /* var */_selectedSkillInfo: SPetSkill;

        protected /* var */_selectedPetSkillItem: PetSkillItem;

        protected /* var */_selectedIndex: int;
    }
